package main

import (
	"context"
	"enotify/internal/xys/notify/push"
	"enotify/pkg/async"
	"enotify/pkg/async/conf"
	"enotify/pkg/async/grpc"
	"fmt"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	conf.Init()
	fmt.Println("start pusher.....")
	pusher := push.NewPush(conf.Conf)
	ctx,cancel := context.WithCancel(context.Background())
	srv := async.NewAsync(ctx,conf.Conf,pusher,[]int32{1,2})
	rpcSrv := grpc.New(conf.Conf.RPCServer,srv)
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
	for {
		s := <-c
		switch s {
		case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
			cancel()
			rpcSrv.GracefulStop()
			pusher.Stop()
			srv.Stop()
			return
		case syscall.SIGHUP:
		default:
			return
		}
	}
}